package mk.company.fin.structure;

import java.util.LinkedList;
import java.util.List;

import mk.company.fin.FinConstants;
import mk.company.fin.model.Konto;

/**
 * Element in the search tree.
 */
public class SearchTreeElement {
	
	private Konto value = null;
	private SearchTreeElement[] next = null;
	private List<Konto> similar = null;

	public Konto getValue() {
		return value;
	}

	public void setValue(Konto value) {
		this.value = value;
	}
	
	public boolean isValid() {
		return value != null;
	}
	
	public List<Konto> getSimilar() {
		return similar;
	}
	
	public void initElement(int index) {
		if (next == null) {
			next = new SearchTreeElement[FinConstants.Application.KONTO_VALID_CHARACTERS_COUNT];
		}
		if (index >= 0 && index < next.length && next[index] == null) {
			next[index] = new SearchTreeElement();
		}
	}

	public SearchTreeElement getElement(int index) {
		if (next != null && index >= 0 && index < next.length) {
			return next[index];
		} else {
			return null;
		}
	}
	
	public void addSimilar(Konto konto) {
		if (similar == null) {
			similar = new LinkedList<Konto>();
		}
		similar.add(konto);
	}
	
}